package org.ysu.shoeShopping.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.ysu.shoeShopping.dao.ShoesInquirysDao;
import org.ysu.shoeShopping.entity.ShoesInquirys;
import org.ysu.shoeShopping.service.ShoesInquirysService;

import javax.annotation.Resource;

/**
 * 商品咨询表(ShoesInquirys)表服务实现类
 *
 * @author makejava
 * @since 2025-09-13 16:59:42
 */
@Service("shoesInquirysService")
public class ShoesInquirysServiceImpl implements ShoesInquirysService
{
    @Resource
    private ShoesInquirysDao shoesInquirysDao;

    /**
     * 通过ID查询单条数据
     *
     * @param sqid 主键
     * @return 实例对象
     */
    @Override
    public ShoesInquirys queryById(Integer sqid) {
        return this.shoesInquirysDao.queryById(sqid);
    }

    /**
     * 分页查询
     *
     * @param shoesInquirys 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ShoesInquirys> queryByPage(ShoesInquirys shoesInquirys, PageRequest pageRequest) {
        long total = this.shoesInquirysDao.count(shoesInquirys);
        return new PageImpl<>(this.shoesInquirysDao.queryAllByLimit(shoesInquirys, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param shoesInquirys 实例对象
     * @return 实例对象
     */
    @Override
    public ShoesInquirys insert(ShoesInquirys shoesInquirys) {
        this.shoesInquirysDao.insert(shoesInquirys);
        return shoesInquirys;
    }

    /**
     * 修改数据
     *
     * @param shoesInquirys 实例对象
     * @return 实例对象
     */
    @Override
    public ShoesInquirys update(ShoesInquirys shoesInquirys) {
        this.shoesInquirysDao.update(shoesInquirys);
        return this.queryById(shoesInquirys.getSqid());
    }

    /**
     * 通过主键删除数据
     *
     * @param sqid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer sqid) {
        return this.shoesInquirysDao.deleteById(sqid) > 0;
    }
}
